<template>
  <div class="bgc-default pad-20">
    <div class="bg-color-white pad-20">
      <div class="tabs-box mar-t--10">
        <el-tabs v-model="tabActive" @tab-click="doChangeTab">
          <el-tab-pane :label="'已截停订单(' + stopTotal + ')'" name="stop"></el-tab-pane>
          <template v-if="systemRoleType == '1' || systemRoleType == '2'">
            <el-tab-pane :label="'待分仓订单(' + waitWarehouseTotal + ')'" name="waitWarehouse"></el-tab-pane>
            <el-tab-pane :label="'报关失败订单(' + customsFailedTotal + ')' " name="customsFailed" v-if="crossBorderData.crossBorderBusinessFlag === 1 "></el-tab-pane>
          </template>
        </el-tabs>
      </div>
      <!-- 已截停订单 -->
      <order-stop v-if="tabActive == 'stop'"></order-stop>
      <!-- 待分仓订单 -->
      <order-wait-warehouse v-if="tabActive == 'waitWarehouse'"></order-wait-warehouse>
      <!-- 报关失败订单 -->
      <order-custom-failed v-if="tabActive == 'customsFailed'"></order-custom-failed>
    </div>
  </div>
</template>


<script>
import orderStop from './order-stop'
import orderWaitWarehouse from './order-wait-warehouse'
import orderCustomFailed from './order-custom-failed'
import { statApartOrder } from '@/api/goods/apartOrder'
import {
  getByEnterpriseId
} from '@/api/user/enterprise'
export default {
  components: {
    orderStop, orderWaitWarehouse, orderCustomFailed
  },
  data() {
    return {
      tabActive: 'stop',
      stopTotal: 0,
      waitWarehouseTotal: 0,
      customsFailedTotal: 0,
      systemRoleType: '',
      crossBorderData: {}
    }
  },
  created() {
    this.systemRoleType = this.getSystemRoleType()
    this.initCount()
    getByEnterpriseId(this.getEnterpriseId()).then(response => {
      this.crossBorderData = response.data
    })
  },
  methods: {

    // tab切换事件
    doChangeTab() {
      switch (this.tabActive) {
        case 'stop':
        case 'waitWarehouse':
        case 'customsFailed':
          this.initCount()
          break
        default:
      }
    },
    // 统计
    initCount() {
      const form = {
        enterpriseId: this.getEnterpriseId(),
        supplierId: this.getSupplierId(),
        warehouseId: this.getWarehouseId()
      }
      statApartOrder(form).then(response => {
        if (response.isError) return
        this.waitWarehouseTotal = response.data[95]
        this.stopTotal = response.data[99]
        this.customsFailedTotal = response.data[1000]
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>
